import { addTodo, loadTodos, TODO_FEATURE_KEY ,selectTodoList} from "../store/todos.slice";
import { useDispatch, useSelector } from "react-redux";
import { useEffect } from 'react';
function App() {
  const dispatch = useDispatch();
  const todos = useSelector(selectTodoList);
  useEffect(() => {
    dispatch(loadTodos("http://localhost:3001/todos"))
  }, [])
  return (
    <div className="App">
      <button onClick={() => dispatch(addTodo({ title: "11" }))}>添加任务</button>
      <ul>
        {
          todos.map((item,index)=>(<li key={item.cid}>{item.title}</li>))
        }
      </ul>
    </div>
  );
}

export default App;
